//package http;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.util.Map;
//
///**
// * Created by luoqifei on 17-2-14.
// */
//public class HttpClient {
//    public static final Logger LOG = LoggerFactory.getLogger(HttpClient.class);
//    public static String getURL(Configuration conf) {
//        String url = conf.getString(ParamNames.REST_DATA_SERVICE_URL);
//        if (url == null || "".equals(url)) {
//            LOG.error("Configuration rest.data.service.url is {}." + url);
//        }
//        if (url != null && url.endsWith("/")) {
//            LOG.warn("Configuration rest.data.service.url={}, we don't recommend this setting end with / ." + url);
//            url = url.substring(0, url.length() - 1);
//        }
//        return url;
//    }
//    public static SimpleHttpResponse get(Configuration conf, Map<String, String> headers){
//        StringBuilder requestUrl = new StringBuilder();
//        if (getURL(conf) == null || "".equals(getURL(conf))) {
//            return null;
//        }
//        //1.1 get the sdm rest base url
//        requestUrl.append(getURL(conf));
//        //1.2 get the special url path
//        requestUrl.append(conf.getString(ParamNames.URL_SELECTED_CHILD_PATH));
//        //1.3 get rest data
//        SimpleHttpResponse response = null;
//        int retryTime = 0;
//        do {
//            try {
//                LOG.info("start to get rest data from URL: "+requestUrl.toString());
//                response = Requests.get(requestUrl.toString(), headers);
//            } catch (RequestException e) {
//                e.printStackTrace();
//            }
//            if (response == null || response.getStatusCode() != 200) {
//                LOG.error("Fail to get rest data from {} for {} , at {} times.", requestUrl.toString(),
//                        response == null ? "response == null" : "getStatusCode() != 200", retryTime + 1);
//                try {
//                    Thread.sleep(Constants.SDM_REST_API_SLEEP_TIME);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                retryTime++;
//            } else {
//                retryTime = Constants.SDM_REST_API_RETRY_TIMES;
//            }
//        }
//        while ((response == null || response.getStatusCode() != 200) && retryTime < Constants.SDM_REST_API_RETRY_TIMES);
//        return response;
//    }
//}
